# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import os
Base_Dir = 'D:/user/Desktop/pic'


class BQGPipeline:

    def process_item(self, item, spider):
        file_name = os.path.join(Base_Dir, f'{item.get("txt_name")}.txt')
        # file_name = f'{item.get("txt_name")}.txt'
        with open(f'{file_name}', 'a', encoding='utf-8') as f:
            # f.write(item.get("txt_name"))
            # f.write('\n')
            f.write(item.get("txt_content"))
        return item
